﻿--|--------------------------------------------------------------------------------
--| [UpdatePerson] - Insert Procedure Script for Game
--|--------------------------------------------------------------------------------
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id (N'[dbo].[UpdatePerson]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1) 
  DROP PROCEDURE [dbo].[UpdatePerson]
GO

CREATE PROCEDURE [dbo].[UpdatePerson]
(
	@ID int, 
	@Name nvarchar(50), 
	@Description nvarchar(50), 
--	@Photo int, 
	@MaxSendingPause int,
	@FullName nvarchar(250),
	@BirthDate datetime,
	@TeamPhone nvarchar(50),
	@OtherPhones nvarchar(50),
	@ICQ nvarchar(50),
	@Skype nvarchar(50),
	@OtherIMs nvarchar(50),
	@Radio nvarchar(50),
	@Tracker nvarchar(50),
	@OtherDevices nvarchar(250))
AS
	SET NOCOUNT ON

UPDATE dbo.Entity SET 
	Name = @Name, 
	Description = @Description, 
	--Photo = @Photo, 
	MaxSendingPause = MaxSendingPause
	WHERE ID = @ID

DELETE FROM dbo.EntityAttribute
WHERE EntityID = @ID 
	AND EntityAttributeTypeID IN ('FNAME','BIRTH','TPHONE','OPHONES','ICQ','SKYPE','IM','TRAN','TRACK','DEVS')

INSERT INTO dbo.EntityAttribute (EntityID, EntityAttributeTypeID, Value)
		     SELECT @ID, 'FNAME', @FullName 
UNION ALL SELECT @ID, 'BIRTH', CONVERT(nvarchar,@BirthDate)
UNION ALL SELECT @ID, 'TPHONE', @TeamPhone
UNION ALL SELECT @ID, 'OPHONES', @OtherPhones
UNION ALL SELECT @ID, 'ICQ', @ICQ
UNION ALL SELECT @ID, 'SKYPE', @Skype
UNION ALL SELECT @ID, 'IM', @OtherIMs
UNION ALL SELECT @ID, 'TRAN', @Radio
UNION ALL SELECT @ID, 'TRACK', @Tracker
UNION ALL SELECT @ID, 'DEVS', @OtherDevices
GO
 